﻿using App.Core.Data;
using App.Core.ServiceImpls;
using App.Core.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace AppTemplate.UI.Sys
{
    internal static class ManualServiceRegister
    {
        /// <summary>
        /// 手动注册服务
        /// </summary>
        /// <param name="serviceCollection">serviceCollection</param>
        /// <param name="configuration">configuration</param>
        internal static void Register(IServiceCollection serviceCollection,IConfiguration configuration)
        {
            //注册EF DbContext
            serviceCollection.AddDbContext<AppDbContext>(opt =>
            {
                var conStr = configuration.GetConnectionString("SqlServer");
                opt.UseSqlServer(conStr);
            }, ServiceLifetime.Transient);

            //注册AutoMapper Profile
            serviceCollection.AddAutoMapper(cfg =>
            {
                cfg.AddProfile<MapperProfile>();
            });

            //***MockDataUserService使用了InjecteAttribute来自动注入，因此无需手动配置注入
            //serviceCollection.AddTransient<IUserService, MockDataUserService>();

        }
    }
}
